<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="设备编码" prop="code"
                :rules="[
                 ]">
              <el-input v-model="inputForm.code" placeholder="请填写设备编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="厂" prop="factory"
                :rules="[
                 ]">
              <el-input v-model="inputForm.factory" placeholder="请填写厂"     ></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="设备编码" prop="equipmentCoding"
                :rules="[
                 ]">
              <el-input v-model="inputForm.equipmentCoding" placeholder="请填写设备编码"     ></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="异常区域" prop="warningArea"
                :rules="[
                 ]">
              <el-input v-model="inputForm.warningArea" placeholder="请填写异常区域"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="异常设备" prop="warningObject"
                :rules="[
                 ]">
              <el-input v-model="inputForm.warningObject" placeholder="请填写异常设备"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="异常信息" prop="warningInformation"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.warningInformation" placeholder="请填写异常信息"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="异常等级" prop="warningLevel"
                :rules="[
                 ]">
                <el-select v-model="inputForm.warningLevel" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('check_abnormal_level')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="第一责任人" prop="firstUser.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.firstUser.id" @getValue='(value) => {inputForm.firstUser.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工号" prop="userId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.userId" placeholder="请填写工号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="检修负责人员" prop="checkPeople"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkPeople" placeholder="请填写检修负责人员"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="完成时间" prop="finishTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.finishTime" placeholder="请填写完成时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务状态" prop="taskStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.taskStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('check_state')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          code: '',
          factory: '',
          equipmentCoding: '',
          warningArea: '',
          warningObject: '',
          warningInformation: '',
          warningLevel: '',
          firstUser: {
            id: ''
          },
          userId: '',
          checkPeople: '',
          finishTime: '',
          taskStatus: '',
          remarks: ''
        }
      }
    },
    components: {
      UserSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建点检异常数据`
        } else if (method === 'edit') {
          this.title = '修改点检异常数据'
        } else if (method === 'view') {
          this.title = '查看点检异常数据'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/check/checkabnormal/checkAbnormal/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.checkAbnormal)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/check/checkabnormal/checkAbnormal/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>